﻿using Hotel.DAL;
using Hotel.Model.Store;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hotel.BLL
{
    public class StoreBLL
    {
        StoreDAL dal;
        public StoreBLL(StoreDAL dal)
        {
            this.dal = dal;
        }

        /// <summary>
        /// 增加门店
        /// </summary>
        /// <param name="info">门店的实体类</param>
        /// <returns>返回影响的行数</returns>
        public int PostAddStore(T_Store info)
        {
            try
            {
                //1.名字是否重复
                int r = dal.SearchStoreName(info.StoreName);
                if (r > 0)
                {
                    return -1;
                }else
                {
                    int res = dal.PostAddStore(info);
                    if (res > 0)
                    {
                        return 1;
                    }
                    else
                    {
                        return -2;
                    }
                }
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 获取门店列表
        /// </summary>
        /// <returns></returns>
        public List<T_Store> GetStoreList()
        {
            try
            {
                List<T_Store> list = dal.GetStoreList();
                return list;
            }
            catch (Exception)
            {

                throw;
            }

        }

        /// <summary>
        /// 删除门店
        /// </summary>
        /// <param name="id">门店的id</param>
        /// <returns>返回影响的行数</returns>
        public int GetDelStoreItem(int id)
        {
            try
            {
                int res = dal.GetDelStoreItem(id);
                if (res > 0)
                {
                    return 1;
                }
                else
                {
                    return -2;
                }

            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 获取所有门店的销售信息
        /// </summary>
        /// <returns></returns>
        public IQueryable GetStoreCountList(int? id = null)
        {
            try
            {
                var list = dal.GetStoreCountList(id);

                return list;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
